<template>
  <div class="tool-bar-drag">
    <div class="tool-bar">
      <div class="function-icon-list">
        <v-icon
          v-if="toolBarIsFold"
          class="icon-item"
          iconClass="icon-jiantou_yemian_xiangzuo"
          title="展开"
          @click="unFold"
        ></v-icon>
        <v-icon
          class="icon-item"
          iconClass="icon-jiantou_yemian_xiangyou"
          title="折叠"
          v-if="!toolBarIsFold"
          @click="fold"
        ></v-icon>
        <template v-if="!toolBarIsFold">
          <v-icon class="icon-item" iconClass="icon-yanse" title="主题颜色"></v-icon>
          <v-icon class="icon-item" iconClass="icon-quanping1" title="全屏"></v-icon>
        </template>
      </div>
      <div class="user-info">
        <span class="user-name">{{ userInfo.nickName ? userInfo.nickName : '' }}</span>
        <a-dropdown>
          <img class="user-header" src="../../assets/images/header.png" />
          <template #overlay>
            <a-menu @click="onClick">
              <a-menu-item key="user">
                <div>个人中心</div>
              </a-menu-item>
              <a-menu-item key="logout">
                <div>退出登录</div>
              </a-menu-item>
            </a-menu>
          </template>
        </a-dropdown>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useStore } from 'vuex'
import { computed, VNodeChild } from 'vue'
import { useRouter } from 'vue-router'
const store = useStore()
const router = useRouter()
let userInfo: any = computed(() => store.state.common.userInfo)
let toolBarIsFold: any = computed(() => store.state.common.toolBarIsFold)
// 展开
const unFold = () => {
  store.commit('setCommonStore', {
    toolBarIsFold: false
  })
}
// 折叠
const fold = () => {
  store.commit('setCommonStore', {
    toolBarIsFold: true
  })
}

interface MenuInfo {
  key: string;
  keyPath: string[];
  item: VNodeChild;
  domEvent: MouseEvent;
}
const onClick = ({ key }: MenuInfo) => {
  if (key === 'logout') {
    store.commit('setCommonStore', {
      token: ''
    })
    router.push('/login')
  }
}
</script>

<style lang="less" scoped>
.tool-bar-drag {
  position: fixed;
  z-index: 1070;
  right: 10px;
  top: 15px;
  cursor: pointer;
  user-select: none;
  height: 40px;
  .tool-bar {
    display: flex;
    height: 40px;
    padding: 0 4px;
    align-items: center;
    background: @theme-bac-color;
    box-shadow: 0 6px 12px rgba(115, 119, 120, 0.66);
    border-radius: 40px;
    color: white;
    .user-info {
      .user-header {
        height: 32px;
        width: 32px;
        margin-left: 10px;
      }
    }
    .function-icon-list {
      padding: 0 10px;
      display: inline-block;
    }

    :deep(.icon-item) {
      font-size: 18px;
      font-weight: bold;
      cursor: pointer;
      margin-right: 6px;
    }
  }
}
</style>
